package ch.selise.archtool.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;

import ch.selise.archtool.lib.HouseBuilder;
import ch.selise.archtool.lib.HouseBuildingCompany;
import ch.selise.archtool.lib.product.House;
import ch.selise.archtool.ui.controller.MainUIController;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ArchWindow extends JFrame {

	private JPanel contentPane;
	private MainUIController controller = new MainUIController();
	
	public MainUIController getController(){return controller;}
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ArchWindow frame = new ArchWindow(null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ArchWindow(Context context) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		JButton btnSingleStoryBuildingButton = new JButton("Single Story Building");
		btnSingleStoryBuildingButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				controller.getBuilder(MainUIController.SIMPLE);
			}
		});
		
		JButton btnMultiStoryBuilding = new JButton("Multi Story Building");
		
		JButton btnBuild = new JButton("Build");
		btnBuild.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					controller.buildHouse();
				} catch (Exception e) {
					e.printStackTrace();
				}
				
			}
		});
		contentPane.add(btnSingleStoryBuildingButton);
		contentPane.add(btnMultiStoryBuilding);
		contentPane.add(btnBuild);
		
		if (context != null) {
			contentPane.add(context.getDoneButton());
			contentPane.add(context.getCancleButton());
		}
		
		/*GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
						.addComponent(btnNewButton_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(btnSingleStoryBuildingButton, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
					.addContainerGap(295, Short.MAX_VALUE))
				.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
					.addContainerGap(325, Short.MAX_VALUE)
					.addComponent(btnBuild)
					.addContainerGap())
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(btnSingleStoryBuildingButton)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnNewButton_1)
					.addPreferredGap(ComponentPlacement.RELATED, 136, Short.MAX_VALUE)
					.addComponent(btnBuild)
					.addGap(30))
		);
		contentPane.setLayout(gl_contentPane);*/
		//BorderLayout borderLayout = new BorderLayout();
		
		
	}
}
